package com.yiguo.realtime.Tests

import java.text.SimpleDateFormat
import java.time.{Instant, LocalDate, LocalDateTime, ZoneId}
import java.time.format.DateTimeFormatter
import java.util.Date

object TimeChange{
  def main(args: Array[String]): Unit = {
    val ts = System.currentTimeMillis()
    val format1 = new SimpleDateFormat("yyyy-MM-dd")
    val format2 = new SimpleDateFormat("yyyy-MM-dd hh")

    val nowdate = new Date(ts)

    val time = format1.format(nowdate)
    val time2 = format2.format(nowdate)
    println(time)
    println(time2)

    //存在问题
    //          有线程安全问题
          //          效率低
    println("==================================新的dateAPI==========================================")
    val formatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd")
    val formatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd hh")

    val localdatetime = LocalDateTime.ofInstant(Instant.ofEpochMilli(ts), ZoneId.of("Asia/Shanghai"))
    println(localdatetime.format(formatter1))
    println(localdatetime.format(formatter2))

    println(localdatetime.getHour)
  }

}
